package service

import (
	ClickHouse "gin/database"
	"gin/model"
)

type Module struct {
}

// ModuleMapByCode 模块字段通过code索引
func ModuleMapByCode() (res map[string]*model.Module, err error) {
	var ModuleList []model.Module
	res = make(map[string]*model.Module)
	err = ClickHouse.DB.Model(&model.Module{}).Find(&ModuleList).Error
	for i, v := range ModuleList {
		res[v.Code] = &ModuleList[i]
	}
	return
}

// ModuleByCode Code查询module
func ModuleByCode(code string) (res *model.Module) {
	m, _ := ModuleMapByCode()
	if _, ok := m[code]; !ok {
		return
	}
	return m[code]
}
